package cluster

import (
	"go-redis/go-redis/interface/resp"
	"go-redis/go-redis/resp/reply"
)

func FlushDB(clusterDatabase *ClusterDatabase, connection resp.Connection, cmdArgs [][]byte) resp.Reply {

	replies := clusterDatabase.broadcast(connection, cmdArgs)
	var errReply reply.ErrorReply

	for _, r := range replies {
		if reply.IsErrorReply(r) {
			errReply = r.(reply.ErrorReply)
			break
		}
	}
	if errReply == nil {
		return &reply.OkReply{}
	}
	return reply.MakeErrReply("error occurs: " + errReply.Error())
}
